package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.HomeHeadFuncResponse;
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo;
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfo;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/3 14:34
 * description:
 */
class ApphomeFinanceGridAdapter extends RecyclerView.Adapter<ApphomeFinanceGridAdapter.ApphomeFinanceGridHolder> {
    private Context mContext;
    private AreaInfo viewData;


    public ApphomeFinanceGridAdapter(Context mContext) {
        this.mContext = mContext;
    }


    private BaseInterface baseInterface;

    public interface BaseInterface {
        public void onClick(View view, String url, String syslabl, int need_header, String s, AdInfo bean);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }

    @Override
    public ApphomeFinanceGridHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.home_finance_grid_view, parent, false);
        return new ApphomeFinanceGridHolder(view);
    }



    @Override
    public void onBindViewHolder(ApphomeFinanceGridHolder holder, final int position) {
        if (viewData != null) {

            holder.itemTv.setText(viewData.getAdInfoVoList().get(position).getResource_name());

                Glide.with(mContext)
                        .load(viewData.getAdInfoVoList().get(position).getResource_url())
                        .into(holder.itemIv);

            holder.viewLL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdInfo bean = viewData.getAdInfoVoList().get(position);
                    String url = bean.getLink_url();

                     baseInterface.onClick(v, url, bean.getSys_label(), bean.getNeed_header(),bean.getResource_id()+"",bean);


                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return viewData.getAdInfoVoList().size();
    }

    public void setViewData(AreaInfo viewData) {

        this.viewData = viewData;
    }


    public static class ApphomeFinanceGridHolder extends RecyclerView.ViewHolder {

        private final ImageView itemIv;
        private final TextView itemTv;
        private final LinearLayout viewLL;

        public ApphomeFinanceGridHolder(View itemView) {
            super(itemView);
            itemIv = (ImageView) itemView.findViewById(R.id.finance_grid_icon);
            itemTv = (TextView) itemView.findViewById(R.id.finance_grid_text);
            viewLL = (LinearLayout) itemView.findViewById(R.id.finance_grid_ll);
        }
    }

}
